//
//  ViewController.m
//  ScrollView练习一个需求
//
//  Created by 蒋俊 on 16/8/27.
//  Copyright © 2016年 蒋俊. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>

/**<#注释#>*/
@property (nonatomic , strong) UIView *leftBar;

@property (nonatomic , strong) UIView *topBar;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //快速创建个scrollView
    UIScrollView *scrollView = [[UIScrollView alloc]init];
    scrollView.frame = self.view.bounds;
    
    [self.view addSubview:scrollView];
    scrollView.delegate = self;
    
    CGFloat contentW = 1000;
    CGFloat contentH = 1000;
    
    CGFloat barSpacing = 50;
    
   
    //右下角内容
    UIView *contentView = [[UIView alloc]init];
    contentView.frame = CGRectMake(barSpacing,barSpacing, contentW, contentH);
    contentView.backgroundColor = [UIColor yellowColor];
    [scrollView addSubview:contentView];
  
    //顶部条
    UIView *topBar = [[UIView alloc]init];
    topBar.frame = CGRectMake(barSpacing, 0, contentW, barSpacing);
    topBar.backgroundColor = [UIColor redColor];
    [scrollView addSubview:topBar];
    self.topBar = topBar;
    //左边条
    UIView *leftBar = [[UIView alloc]init];
    leftBar.frame = CGRectMake(0,barSpacing, barSpacing, contentH);
    leftBar.backgroundColor = [UIColor blueColor];
    [scrollView addSubview:leftBar];
    self.leftBar = leftBar;
    
    //遮盖
    UIView *cover = [[UIView alloc]init];
    cover.frame = CGRectMake(0,0, barSpacing, barSpacing);
    cover.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:cover];
    
    //设置ScrollView的contentSize
    scrollView.contentSize = CGSizeMake(contentW + barSpacing, contentH + barSpacing);
    //取消ScrollView的弹簧效果
    scrollView.bounces = NO;
    
    
}

#pragma mark -- ScrollVive代理方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //处理顶部控件不跟随黄色内容控件动的原理:只需把顶部控件的Y值始终设置为scrollView的ContentOffest.y
    CGRect topF = self.topBar.frame;
    topF.origin.y = scrollView.contentOffset.y;
    self.topBar.frame = topF;
    //处理向右滑动的时候，左边条不动
    CGRect leftF = self.leftBar.frame;
    leftF.origin.x = scrollView.contentOffset.x;
    self.leftBar.frame = leftF;
    
}



























@end
